<%--
  Created by IntelliJ IDEA.
  User: 123
  Date: 2020/11/4
  Time: 17:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form >
    账号:<input type="text" name="name" onblur="doAjax()"><span id="state"></span>
</form>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.11.1.js"></script>
<script type="text/javascript">
    function doAjax() {
        var xhr=new XMLHttpRequest();
        var name = $(":input").val();
        xhr.open("post","${pageContext.request.contextPath}/mains/mains_ma?name="+name)
        //设置回调函数
        xhr.onreadystatechange=function () {
            if (xhr.readyState==4){
                if (xhr.status==200){
                    var c= xhr.responseText
                    if (c=="true"){
                    $("#state").html("该用户已被注册")
                }
                    if (c=="false") {
                    $("#state").html("该用户名可用")
                }
            }
        }
    }
        xhr.send();
    }
</script>
</body>
</html>
